<?php
$name=isset($_GET['name'])?$_GET['name']:null;
if(isset($_POST['submit']))
{
	Page::save_page_content_by_name($name,$_POST['page_content']);
	if($_POST['submit']=='Lưu & Đóng')
		Common::header_location(null,null,"$('#btn_close').trigger('click')");
}
$array=Page::fetch_page_by_name($name);
$page_content=$array['page_content'];
$page_type=$array['page_type']; 
?>

<?php if($page_type==1){?>
<script type="text/javascript" src="<?php echo BASE_URL?>ext/js/ckeditor/ckeditor.js" ></script>
<script>
	$(document).ready(function(){
		var ckfinder_url='<? echo BASE_URL?>ext/js/ckfinder/';				
		CKEDITOR.replace($("#editor")[0], { 
		height:'500px'
		, width:'780px'
		,toolbar:'Full'					
		,filebrowserBrowseUrl:ckfinder_url+'ckfinder.html'
		,filebrowserImageBrowseUrl:ckfinder_url+'ckfinder.html?type=images'
		,filebrowserFlashBrowseUrl:ckfinder_url+'ckfinder.html?type=flash'
		,filebrowserUploadUrl:ckfinder_url+'core/connector/php/connector.php?command=QuickUpload&type=files'
		,filebrowserImageUploadUrl:ckfinder_url+'core/connector/php/connector.php?command=QuickUpload&type=images'
		,filebrowserFlashUploadUrl:ckfinder_url+'core/connector/php/connector.php?command=QuickUpload&type=flash'
		});					
	})
</script>
<?php }?>

<style>
	#editor{ width:788px;height:500px}
</style>

<form method='post'>
	Nội dung<br/>
	<textarea name='page_content' id='editor'><?php echo $page_content;?></textarea><br/>
	<div style='text-align:right;padding:4px'>
		<input type='submit' value='Lưu' name='submit'/>
		<input type='submit' value='Lưu & Đóng' name='submit'/>
		<input type='button' value='Đóng' id='btn_close' onclick="
			if(window.opener)
			{
				window.opener.location.reload();
				window.close();
			}
			else 
			{
				window.location='index.php';
			}
		"/>
	</div>
</form>